package com.yonyou.pmclouds.messagenotice.constructor.impl;

import com.yonyou.pmclouds.alter.entity.AlterVO;
import com.yonyou.pmclouds.alter.rmiitf.AlterQuery;
import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.Entity;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.messagenotice.entity.MessageNoticeVO;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AlterNoticeConstructor extends AbstractMessageNoticeConstructor {

    private final AlterQuery alterQuery;

    private final ProjectSimpleQuery projectSimpleQuery;

    @Autowired
    public AlterNoticeConstructor(AlterQuery alterQuery, ProjectSimpleQuery projectSimpleQuery) {
        this.alterQuery = alterQuery;
        this.projectSimpleQuery = projectSimpleQuery;
    }


    @Override
    protected MessageNoticeVO[] generateContent(Entity vo) throws BusinessException {
        MessageNoticeVO noticeVO = coverBusinessVOToMessageVO(vo);
        if(noticeVO == null){
            return null;
        }
        // 您提交的【变更申请/签证申请】已审批通过
        // 您提交的【变更申请/签证申请】已被驳回
        AlterVO alterVO = alterQuery.getById(noticeVO.getRelateKey());
        ProjectVO projectVO = projectSimpleQuery.queryProject(alterVO.getPk_project());

        String prefix = getApprovalPrefixMessage(alterVO.getBillstatus());
        String messageContent = APPROVAL_PREFIX_MESSAGE + "[" +
                 alterVO.getCategoryName()+ "]的变更申请，" + prefix;

        noticeVO.setMessageTitle(projectVO.getSname());
        noticeVO.setMessageReceiver(alterVO.getCreator());
        noticeVO.setPkTenant(alterVO.getPkTenant());
        noticeVO.setMessageContent(messageContent);
        noticeVO.setRelateType(alterVO.getBill_type());

        return new MessageNoticeVO[]{noticeVO};
    }

    @Override
    public String getRelateType() {
        return BillTypeConst.ALTER_BILLTYPE;
    }
}
